package jps.result;

import jps.datastore.OID;
import edu.pjwstk.jps.datastore.IOID;
import edu.pjwstk.jps.datastore.ISBAObject;
import edu.pjwstk.jps.datastore.ISimpleObject;
import edu.pjwstk.jps.result.IReferenceResult;

public class ReferenceResult extends SingleResult implements IReferenceResult {
	private IOID OIDValue;
	private ISBAObject value;

	public ReferenceResult(IOID oIDValue) {
		super();
		OIDValue = oIDValue;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ReferenceResult other = (ReferenceResult) obj;
		if (OIDValue == null) {
			if (other.OIDValue != null)
				return false;
		} else if (!OIDValue.equals(other.OIDValue))
			return false;
		return true;
	}

	@Override
	public IOID getOIDValue() {
		// TODO Auto-generated method stub
		return OIDValue;
	}

	@Override
	public String toString() {
		if (value instanceof ISimpleObject<?>) {
			return "ReferenceResult [" + ((OID) value.getOID()).GetValue()
					+ ", " + ((ISimpleObject<?>) value).getName() + ", \""
					+ ((ISimpleObject<?>) value).getValue().toString() + "]";
		} else {
			return "ReferenceResult [" + ((OID) value.getOID()).GetValue()
					+ " " + value.getName().toString() + "]";
		}

	}

	public static ReferenceResult createFromSBAObject(ISBAObject o) {
		ReferenceResult refObj = new ReferenceResult(o.getOID());
		refObj.setValue(o);

		return refObj;
	}

	public void setValue(ISBAObject aValue) {
		value = aValue;
	}

}
